package com.sign2024.sign2024project.capitalconstruction.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sign2024.sign2024core.common.constants.CommonConstants;
import com.sign2024.sign2024core.common.exeception.CommonException;
import com.sign2024.sign2024core.common.utils.StringUtils;
import com.sign2024.sign2024core.entry.capitalconstruction.JjRecordCollect;
import com.sign2024.sign2024project.capitalconstruction.mapper.JjRecordCollectMapper;
import com.sign2024.sign2024project.capitalconstruction.param.JjParam;
import com.sign2024.sign2024project.capitalconstruction.service.JjRecordCollectService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基建获取记录表数据 业务层
 *
 * @author yujie
 * @data 2024/8/23 13:08
 */
@Service
public class JjRecordCollectServiceImpl implements JjRecordCollectService {

    @Resource
    private JjRecordCollectMapper jjRecordCollectMapper;

    @Override
    public void insertBatchJjRecordCollect(List<JjRecordCollect> list, Integer taskId) {
        if (StringUtils.isEmpty(list)) {
            throw new CommonException(CommonConstants.ERROR, "任务id为空");
        } else {
            // 批量新增
            jjRecordCollectMapper.insertBatchJjRecordCollect(list, taskId);
        }
    }

    @Override
    public void deleteByTaskId(Integer taskId) {
        jjRecordCollectMapper.deleteByTaskId(taskId);
    }

    @Override
    public Page<JjRecordCollect> pageJjRecord(JjParam param) {
        Integer offset = (param.getPageNum() - 1) * param.getPageSize();
        param.setOffset(offset);

        // 分页查询
        Page<JjRecordCollect> page = new Page<>(param.getPageNum(), param.getPageSize());
        List<JjRecordCollect> List = jjRecordCollectMapper.selectJjRecordByPage(param);

        // 页码
        page.setCurrent(param.getPageNum());
        page.setSize(param.getPageSize());

        // 总记录数
        Long aLong = jjRecordCollectMapper.pageJjRecordCount(param);
        page.setTotal(aLong);
        page.setRecords(List);

        return page;
    }
}
